﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using DevKnightlie.WPF.AutoForm.FieldDefinitions;

namespace DevKnightlie.WPF.AutoForm.Demo
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private void ModelObjectFormDefiner_FieldDefinitionCreated(object sender, FieldDefinitionEventArgs e)
        {
            if (e.PropertyName != null && e.PropertyName.Equals("PhoneNumber"))
            {
                e.FieldDefinition.Title = "Phone Number";
            }
            if (e.PropertyName != null && e.PropertyName.Equals("SkillsList"))
            {
                e.FieldDefinition.Newline = true;
                e.FieldDefinition.StretchMode = BaseFieldDefinition.StretchType.Full;
            }
            if (e.PropertyName != null && e.PropertyName.Equals("Notes"))
            {
                e.FieldDefinition.StretchMode = BaseFieldDefinition.StretchType.Full;
            }
            
        }

        private void ModelObjectFormDefiner_FieldDefinitionRequired(object sender, FieldDefinitionEventArgs e)
        {
            if (e.PropertyName != null)
            {
                if (e.PropertyName.Equals("PhoneNumber"))
                {
                    // Create a RegEx field for phone number
                    RegexTextFieldDefinition def = new RegexTextFieldDefinition();
                    def.RegexPattern = @"[0-9]{10,11}";
                    e.FieldDefinition = def;
                }
                else if (e.PropertyName.Equals("EmailAddres"))
                {
                    // \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
                    // Create a RegEx field for email address
                    RegexTextFieldDefinition def = new RegexTextFieldDefinition();
                    def.RegexPattern = @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
                    e.FieldDefinition = def;
                }
                else if (e.PropertyName.Equals("DialogExample"))
                {
                    DialogFieldDefinition def = new DialogFieldDefinition();
                    def.DialogAction = (object exiting) => { return DateTime.Now.ToString(); };
                    e.FieldDefinition = def;
                }
            }
        }
    }
}
